package com.myz.rabbitmq.study6;

import com.myz.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.*;

public class ReceiveLogsDirect01 {
    // exchange name
    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        // get channel
        Channel channel = RabbitMqUtils.getChannel();
        // get temp queue name
//        String queueName = channel.queueDeclare().getQueue();
        // declare a exchange (exchangName,ExchangeType)
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        // declare a queue (queueName
        channel.queueDeclare("console",false,false,false,null);

        // binding exchange and queue,(queuename,exchangeName,routing key)
        channel.queueBind("console",EXCHANGE_NAME,"info");
        channel.queueBind("console",EXCHANGE_NAME,"warning");

        System.out.println("waiting receive message");
        DeliverCallback deliverCallback = (var1,var2) -> {
            System.out.println("ReceiveLogsDirect01接收消息:"+new String(var2.getBody(),"UTF-8"));
        };
        channel.basicConsume("console",true,deliverCallback, (CancelCallback) null);

    }

}
